package beans;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

@ManagedBean(name="utenteBean")
@SessionScoped
public class UtenteBean implements Serializable {
	
	@ManagedProperty(value="#{connectionBean}")
	private ConnectionBean connectionBean;
	@ManagedProperty(value="#{messaggioBean}")
	private MessaggioBean messaggioBean;
	private String user="";
	private String password="";
	private boolean loggato=false;
	
	public String getUser() {
		return user;
	}
	public void setUser(String user) {
		this.user = user;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public boolean isLoggato() {
		return loggato;
	}
	public void setLoggato(boolean loggato) {
		this.loggato = loggato;
	}
	public String getLoginPath() {
		if ( isLoggato() )
		{
			return "pretty:gestione";
		}
		
		return "/faces/login.xhtml";
	}
	
	public String getViewPath() {
		if ( isLoggato() )
		{
			return "/faces/gestione.xhtml";
		}
		
		return "/faces/login.xhtml";
	}
	public String getInsEventoPath() {
		if ( isLoggato() )
		{
			return "/faces/insEvento.xhtml";
		}
		
		return "/faces/login.xhtml";
	}
	public String getInsLuogoPath() {
		if ( isLoggato() )
		{
			return "/faces/insLuogo.xhtml";
		}
		
		return "/faces/login.xhtml";
	}
	
	public String getInsFotoPath() {
		if ( isLoggato() )
		{
			return "/faces/insFoto.xhtml";
		}
		
		return "/faces/login.xhtml";
	}
	public String getVediEventiPath() {
		if ( isLoggato() )
		{
			return "/faces/vediEventi.xhtml";
		}
		
		return "/faces/login.xhtml";
	}
	public String getVediLuoghiPath() {
		if ( isLoggato() )
		{
			return "/faces/vediLuoghi.xhtml";
		}
		
		return "/faces/login.xhtml";
	}
	public String getGestLuoghiPath() {
		if ( isLoggato() )
		{
			return "/faces/gestLuoghi.xhtml";
		}
		
		return "/faces/login.xhtml";
	}
	public String getGestEventiPath() {
		if ( isLoggato() )
		{
			return "/faces/gestEventi.xhtml";
		}
		
		return "/faces/login.xhtml";
	}
	
	public String doLogin() {
		

		ConnectionBean connec = getConnectionBean();
		
			boolean loggo = false;
			loggo = connec.doLoginSaxon(getUser(),getPassword());
			if(loggo){
			this.setLoggato(true);
			return "pretty:gestione";
			}else {
				MessaggioBean er  = getMessaggioBean();
				er.setMessaggio("Utente sconosciuto");
				er.setBack("login");
				return "errore";
			}
		
		
}
	public ConnectionBean getConnectionBean()
    {
        return connectionBean;
    }

    public void setConnectionBean(ConnectionBean conn)
    {
        this.connectionBean = conn;
    }


	public MessaggioBean getMessaggioBean() {
		return messaggioBean;
	}

	public void setMessaggioBean(MessaggioBean messaggioBean) {
		this.messaggioBean = messaggioBean;
	}

}
